#ifndef TCPSERVER_H
#define TCPSERVER_H

#include <QObject>
#include <QTcpServer>
#include <iostream>
#include <QList>
#include <QDataStream>
#include <QByteArray>
#include "UserInfo.h"
#include "Game.h"
#include <QMap>

using namespace std;

class TcpServer : public QObject
{
    Q_OBJECT

    QTcpServer mServer;
    quint16 mPort;

    QList<QTcpSocket*> mSocketList;
    QMap<QTcpSocket*,Game*> mSocketMap;
    QList<Game*> mGameList;
    int mAutoRoomID;
    UserInfo mUserInfo;

    Game* findGame(int roomID);
public:
    explicit TcpServer(quint16 port, QObject *parent = 0);
    bool init();
    void removeFromGame(QTcpSocket* socket);
    
signals:

protected slots:
    void newConnection();

    void readData();
    void disconnected();

    void removeGame(Game* game);

    void write_socket(QTcpSocket* socket, const QByteArray &buf);
};

#endif // TCPSERVER_H
